home *** CD-ROM | disk | FTP | other *** search
/ Ham Radio 2000 #1 / Ham Radio 2000.iso / ham2000 / hf / dsp / source / protocol.asm < prev    next >
Encoding:
Assembly Source File  |  1992-09-30  |  4.2 KB  |  209 lines

  1.     page    132,63,1,1
  2.     opt    rc
  3.     title    'LPC Vocoder interface protocol handler'
  4.  
  5. ;***************************************************************
  6. ;* PROTOCOL.ASM -- LPC Vocoder interface protocol handler      *
  7. ;*                                   *
  8. ;* Handles a special serial interface protocol for Vocoder     *
  9. ;*                                   *
  10. ;* Copyright (C) 1992 by Alef Null. All rights reserved.       *
  11. ;* Author(s): Jarkko Vuori, OH2LNS                   *
  12. ;* Modification(s):                           *
  13. ;*    26-Sep-92: corrected negative pitch problem           *
  14. ;*           added block count field to Host-DSP frame   *
  15. ;***************************************************************
  16.  
  17.     section LPCprotocol
  18.     xdef    pro_i,get_blk,put_blk
  19.  
  20.     org    p:
  21.  
  22.     nolist
  23.     include 'macros'
  24.     list
  25.  
  26.  
  27. ; Protocol parameters
  28. sync1    equ    $55                    ; frame sync words
  29. sync2    equ    $aa
  30. blks    equ    20                    ; number of 48-bit block in one frame
  31.  
  32.  
  33. ; Macro to change state (in reader state machine)
  34. nxt    macro    state
  35.     movi    state,x:gstate
  36.     jmp    <get_blk
  37.     endm
  38.  
  39.  
  40. ; Initialize protocol handler data structures
  41. pro_i    movi    gstate0,x:gstate
  42.     movi    1,x:oblkcnt
  43.  
  44.     rts
  45.  
  46.  
  47. ; Get one LPC parameter block (if there are any available)
  48. ;   returns C if no block available
  49. ;       NC if block available
  50. get_blk jsr    <getc
  51.     jcs    <getend
  52.     move            x:gstate,r0
  53.     nop
  54.     jmp    (r0)
  55.  
  56. ; State 0 - first sync word
  57. gstate0 move            #>sync1,a
  58.     cmp    x0,a
  59.     jne    <get_blk
  60.     nxt    gstate1
  61.  
  62. ; State 1 - second sync word
  63. gstate1 move            #>sync2,a
  64.     cmp    x0,a
  65.     jne    <gs1a
  66.     nxt    gstate2
  67. gs1a    nxt    gstate0
  68.  
  69. ; State 2 - flags byte
  70. gstate2 move            x:<flags,a1
  71.     move            #>$ffff00,x1        ; replace lower flag bits
  72.     and    x1,a
  73.     or    x0,a
  74.     move            a1,x:<flags
  75.     nxt    gstate3
  76.  
  77. ; State 3 - p_d byte
  78. gstate3 move            #>128,a            ; check if 8-bit negative number
  79.     cmp    x0,a        x0,x:<p_d
  80.     jgt    <_pos
  81.     asl    a                    ; yes, convert to 24-bit negative number -(256 - x0)
  82.     sub    x0,a
  83.     neg    a
  84.     move            a,x:<p_d
  85. _pos    movi    blks,x:iblkcnt
  86.     nxt    gstate4
  87.  
  88. ; State 4 - first block byte
  89. gstate4 move            #>@cvi(@pow(2,16-1)),x1 ; shift left 16 bits
  90.     mpy    x0,x1,a
  91.     move            a0,x:tmpblk
  92.     nxt    gstate5
  93.  
  94. ; State 5 - second block byte
  95. gstate5 move            #>@cvi(@pow(2,8-1)),x1  ; shift left 8 bits
  96.     mpy    x0,x1,a     x:tmpblk,x0
  97.     move            a0,a1
  98.     or    x0,a
  99.     move            a1,x:tmpblk
  100.     nxt    gstate6
  101.  
  102. ; State 6 - third block byte
  103. gstate6 move            x:tmpblk,a
  104.     or    x0,a
  105.     move            a1,x:tmpblk
  106.     nxt    gstate7
  107.  
  108. ; State 7 - 4th block byte
  109. gstate7 move            #>@cvi(@pow(2,16-1)),x1 ; shift left 16 bits
  110.     mpy    x0,x1,a
  111.     move            a0,x:tmpblk+1
  112.     nxt    gstate8
  113.  
  114. ; State 8 - 5th block byte
  115. gstate8 move            #>@cvi(@pow(2,8-1)),x1  ; shift left 8 bits
  116.     mpy    x0,x1,a     x:tmpblk+1,x0
  117.     move            a0,a1
  118.     or    x0,a
  119.     move            a1,x:tmpblk+1
  120.     nxt    gstate9
  121.  
  122. ; State 9 - last block byte
  123. gstate9 move            x:tmpblk+1,a
  124.     or    x0,a        #>1,x0
  125.     move            a1,x:tmpblk+1
  126.  
  127.     move            x:iblkcnt,a         ; check if end of frame
  128.     sub    x0,a        #>gstate4,x0
  129.     jne    <_gs9a
  130.     move            #blks,a1
  131.     move            #>gstate0,x0
  132. _gs9a    move            a1,x:iblkcnt
  133.     move            x0,x:gstate
  134.  
  135.     move            x:tmpblk,a1         ; return block
  136.     move            a1,x:lpcin
  137.     move            x:tmpblk+1,a1
  138.     move            a1,x:lpcin+1
  139.     andi    #$fe,ccr
  140.  
  141. getend    rts
  142.  
  143.  
  144. ; Send one LPC parameter block
  145. put_blk move            x:oblkcnt,a
  146.     move            #>1,x0
  147.     sub    x0,a        #>blks,x0
  148.     move            a,x:oblkcnt
  149.     jne    _puta
  150.     move            x0,x:oblkcnt
  151.  
  152.     move            #>sync1,x0            ; put header
  153.     jsr    <putc
  154.     move            #>sync2,x0
  155.     jsr    <putc
  156.     move            x:<flags,x0
  157.     jsr    <putc
  158.     move            x:<p_d,x0
  159.     jsr    <putc
  160.  
  161. _puta    move            #lpcout,r0
  162.     jsr    <wordout
  163.     move            #lpcout+1,r0
  164.     jsr    <wordout
  165.  
  166.     rts
  167.  
  168.  
  169. ; Output one word
  170. wordout
  171.     move            x:(r0),a1            ; most significand byte
  172.     lsr    a        #@pow(2,-15),x1        ; this is needed because 24th bit is sign bit
  173.     move            a1,x0
  174.     mpy    x0,x1,a     #>$ff,x0
  175.     and    x0,a
  176.     move            a1,x0
  177.     jsr    <putc
  178.  
  179.     move            x:(r0),x0            ; middle byte
  180.     move            #@pow(2,-8),x1
  181.     mpy    x0,x1,a     #>$ff,x0
  182.     and    x0,a
  183.     move            a1,x0
  184.     jsr    <putc
  185.  
  186.     move            x:(r0),a1            ; lest significand byte
  187.     move            #>$ff,x0
  188.     and    x0,a
  189.     move            a1,x0
  190.     jsr    <putc
  191.  
  192.     rts
  193.  
  194.  
  195. ;****************************
  196. ;*     DATA - AREA        *
  197. ;****************************
  198.  
  199.     org    x:
  200.  
  201. gstate    ds    1
  202. tmpblk    ds    2
  203. iblkcnt ds    1
  204. oblkcnt ds    1
  205.  
  206.     endsec
  207.  
  208.     end
  209.